/**
 * @param {number} n
 * @param {number} k
 * @return {number[][]}
 */
export var combine = function (n, k) {
  const res = []
  dfs(n, k, 1, [], res)
  return res
}

/**
 * @param {number} n
 * @param {number} k
 * @param {number} begin
 * @param {array} path 记录当前路径
 * @param {array} res 保存结果
 */
function dfs(n, k, begin, path, res) {
  if (path.length === k) {
    res.push(path.slice())
    return
  }
  for (let i = begin; i <= n; i++) {
    path.push(i)
    dfs(n, k, i + 1, path, res)
    path.pop()
  }
}
